﻿using NPOI.Util;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using SmartWaterMointerCenter.Models;

namespace SmartWaterMointerCenter.UControls
{
    public partial class UWMPanel : UserControl
    {
        public UWMPanel()
        {
            InitializeComponent();
        }
        //住户编号
        public int ResidentNo { get; set; }
        //住户名称
        public string ResidentName
        {
            get { return lblResidentName.Text; }
            set { lblResidentName.Text = value;}
        }
        //当前读数
        public decimal CurWMRead
        {
            get { return vtxtWMRead.Value; }
            set { vtxtWMRead.Value = value; }
        }

        //本月用水量
        public decimal MonthTotalWM
        {
            get { return vtxtMonthWM.Value; }
            set { vtxtMonthWM.Value = value; }
        }

        private int wState=-1;
        //用水状态
        public int WState
        {
            get { return wState; }
            set { wState = value;
                RefreshState();
            }
        }

        //用水状态刷新处理
        private void RefreshState()
        {
            if(wState==-1)
            {
                cirState.Visible = false;
            }
            else
            {
                cirState.Visible = true;
                if(wState==1)
                {
                    cirState.ForeColor = Color.DodgerBlue;//正常
                }
                else if(wState==2)
                {
                    cirState.ForeColor = Color.Orange;//二级用水
                }
                else
                {
                    cirState.ForeColor = Color.Red;//三级用水
                }

            }
        }

        //初始化住户信息
        public void InitResident(ResidentInfo resident)
        {
            ResidentNo = resident.ResidentNo;
            ResidentName = resident.ResidentName;
            MonthTotalWM = resident.MonthTotalWM;
            CurWMRead = 0;
            WState = -1;
        }

        //更新住户数据
        public void UpdateData(ResidentData data)
        {
            if(data!=null)
            {
                MonthTotalWM = data.ThisMonthWM;
                CurWMRead = data.WMRead;
            }
        }
    }
}
